<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="自定义字段编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customcode">
              <a-input v-model="model.customcode" placeholder="请输入自定义字段编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customname">
              <a-input v-model="model.customname" placeholder="请输入自定义字段名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cutomtype">
              <!-- <a-input v-model="model.cutomtype" placeholder="请选择字段类型"  ></a-input> -->
              <a-select default-value="0" v-model="model.customtype" style="width: 120px" @change="handleChange">
                <a-select-option value="0">
                  文本输入
                </a-select-option>
                <a-select-option value="1">
                  数字
                </a-select-option>
                <a-select-option value="2">
                  日期
                </a-select-option>
                <a-select-option value="3">
                  下拉搜索
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否可见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isvisble">
              <a-checkbox v-model="model.isvisble" placeholder="请选择是否可见"></a-checkbox>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="显示顺序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="showno">
              <a-input v-model="model.showno" placeholder="请输入显示顺序"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否必填" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isvisble">
              <a-checkbox v-model="model.isnotnuLl" placeholder="请选择是否必填"></a-checkbox>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="过滤字典" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customCondition">
              <a-input v-model="model.customCondition" placeholder="请输入customCondition"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'ScmcustomfieldsForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      selectvalue:'0',
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/base/scmcustomfields/add',
        edit: '/base/scmcustomfields/edit',
        queryById: '/base/scmcustomfields/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    handleChange(e){
     this.model.customtype =e;
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
            this.model.scmobjectid=localStorage.getItem("customobjectid")
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>
